import numpy as np
import cv2 as cv
from PIL import Image
import os

LabelDir = "E:\study\cloud detection\shiyandata\jinlabelme\label"


for root, dirs, files in os.walk(LabelDir):
    i = 0
    for file in files:
        path = os.path.join(root, file)
        data = np.array(Image.open(path))
        if len(data.shape) != 2:
            print(file, data.shape)
            i += 1
            assert (data[:, :, 0] == data[:, :, 1]).all() and (data[:, :, 1] == data[:, :, 2]).all()
            data = data[:, :, 0]
            cv.imwrite(path, data)
    print(i)

